package ejercicio7;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;



/**
 * Hello world!
 *
 */
public class Procesador 
{
    public static void main( String[] args )
    {
    	  try {
    			CLexer lex = new CLexer(new ANTLRFileStream(args[0]));
    			CommonTokenStream tokens = new CommonTokenStream(lex);
    			
    			CParser parser = new CParser(tokens);
    			parser.entrada();
    			if((lex.hasErrors()) || (parser.hasErrors()) )
    			{
    				System.out.println("Se encotraron errores al analizar");
    				 List<RecognitionException> errorsLexer = lex.getAllErrors();
    				 List<RecognitionException> errorsParser = parser.getAllErrors();
    				 Iterator<RecognitionException> it = errorsLexer.iterator();
    				 while(it.hasNext()){
    					 System.out.println(it.next());
    				 }
    				 
    				 it = errorsParser.iterator();
    				 while(it.hasNext()){
    					 System.out.println(it.next());
    				 }
    					 
    			}else
    			{
    				System.out.println("Fichero procesado correctamente");
    			}
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (RecognitionException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	    
    }
}
